<template>
  <div>
    <el-table v-loading="loading" :data="data" :element-loading-text="elementLoadingText" fit stripe highlight-current-row>
      <template v-for="(field, index) in fields">
        <el-table-column :key="index" :label="field.lable" align="center" :width="field.width">
          <template slot-scope="scope">
            <slot :name="field.prop" :row="scope.row">
              {{ scope.row[field.prop] }}
            </slot>
          </template>
        </el-table-column>
      </template>
    </el-table>
    <el-pagination
      v-show="pageSize !==0 && total !==0 && pagination_show"
      style="padding-top:20px;float:right;"
      background
      :page-size="pageSize"
      :current-page="pageNo"
      layout="prev, pager, next"
      :total="total"
    />
  </div>
</template>

<script>
/**
* 属性 fields 的类型
interface IField {
  prop: string, // 字段属性
  label: string, // 显示内容
  width: string
}

**/

export default {
  props: {
    fields: {
      required: true,
      type: Array // IField
    },
    pageSize: {
      type: Number,
      default: 20
    },
    pageNo: {
      type: Number,
      default: 1
    },
    total: {
      type: Number,
      default: 20
    },
    elementLoadingText: {
      type: String,
      default: '正在加载中'
    }
  },
  data: function() {
    return {
      loading: true,
      pagination_show: false,
      data: []
    }
  },
  methods: {
    render(data) {
      this.data = data
      if (this.total > this.pageSize) {
        this.pagination_show = true
      }
      this.loading = false
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
